package com.lby.graduation.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lby.graduation.entity.Types;
import com.lby.graduation.mapper.TypesMapper;
import com.lby.graduation.service.TypesService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 李兵耀
 * @since 2020-12-16
 */
@CrossOrigin
@RestController
@RequestMapping("/types")
public class TypesController {
    @Resource
    private TypesService typesService;
    @Resource
    private TypesMapper typesMapper;
    /*添加类型*/
    @GetMapping("/addType")
    public boolean addType(Types types) {
        return typesService.save(types);
    }
   /*userFindType*/
    @RequestMapping("/userFindType")
    public List<Types> userFindType(){
        return typesService.list();
    }
    @RequestMapping("/adminFindType")
    public Map adminFindType(Integer current, Integer size) {
        HashMap<String, Object> map = new HashMap<>();
        Page<Types> typesPage = new Page<>(current, size);
        List<Types> list = typesMapper.selectPageType(typesPage);
        long total = typesPage.getTotal();
        map.put("code", 200);
        map.put("data", list);
        map.put("msg", "查找成功");
        map.put("count", total);
        return map;
    }



    /*通过id删除*/
    @RequestMapping("/deleteType")
    public Map deleteType(Integer typeId) {
        HashMap<String, Object> map = new HashMap<>();
        boolean b = typesService.removeById(typeId);
        if (b = true) {
            map.put("code", 200);
            map.put("msg", "删除成功");
        } else {
            map.put("msg", "删除失败");
        }
        return map;
    }


}
